<template>
 <view class="px32">
    <!-- <u-navbar :is-back="false" title="修改个人中心" :border-bottom="false">
			<view class="u-flex u-row-right" style="width: 100%;">
				<view class="camera u-flex u-row-center">
					<u-icon name="camera-fill" color="#000000" size="48"></u-icon>
				</view>
			</view>
		</u-navbar> -->
    <!-- prop属性主要做表单验证 -->
    <u--form :model="userInfo" ref="uForm" :rules="rules">
			<u-form-item label="姓名" prop="name" required>
				<u-input v-model="userInfo.name" />
			</u-form-item>
		</u--form>
		<u-button @click="submit" type="primary">提交</u-button>
 </view>
</template>

<script>
import { userInfoUpdate, getUserInfo } from '@/config/api'
export default {
  data() {
   return {
     userInfo: {
       name: ''
     },
     rules: {
      'name': {
        type: 'string',
        required: true,
        message: '请填写姓名',
        trigger: ['blur', 'change']
      },
    }
   }
  },
  onLoad() {

  },
  methods: {
    submit() {
      this.$refs.uForm.validate().then(async (valid) => {
        const res = await userInfoUpdate({name: this.userInfo.name})
        // this.$refs.uForm.resetFields()
        // 更新用户信息
        // const userRes = await getUserInfo();
				// this.$u.vuex('vuex_user', userRes)
        this.$u.utils.updateUser()

				this.$u.toast('更新成功')
				setTimeout(() => {
					this.$u.route({
						type: 'navigateBack'
					})
				}, 1000)
      }).catch(errors => {
        console.log(errors)
        uni.$u.toast('校验失败')
      })
    }
  },
  onReady() {
    this.userInfo.name = this.vuex_user.name
  }
}
</script>

<style scoped>
</style>